package com.colin.aiyi.presenter.Imp_de;

import com.colin.aiyi.app.Constant;
import com.colin.aiyi.dao.ImpxUtils3_de.IService;
import com.colin.aiyi.dao.ImpxUtils3_de.ImpSay;
import com.colin.aiyi.dao.ImpxUtils3_de.ImpYuLu;
import com.colin.aiyi.entity.DataEntity;
import com.colin.aiyi.entity.YiJuAndYiShuoEntity;
import com.colin.aiyi.entity.response.YiJuAndYiShuoResponse;
import com.colin.aiyi.ui.Home.mine.IViewHome;
import com.colin.aiyi.presenter.Interface_Derecated.AbsPresenter;

import java.util.List;

/**
 * Created by hl on 2017/6/6.
 */
@Deprecated
public class ImpPHome extends AbsPresenter<YiJuAndYiShuoResponse> {
    IViewHome iViewHome;
    IService<YiJuAndYiShuoResponse> iService;
    private String contentType;
    private int pageNum;
    private boolean pullMore=false;
    private int totalCount;
    private String lastType=Constant.TAB_TYPE_SAY_WACTH;


    /********
     * 获取一说列表
     * @param //pageNum  目标页面
     * @param //cType  类型
     */

    @Override
    public void getAllT(String... type) {
        this.contentType=type[type.length-1];
        this.pageNum= Integer.parseInt(type[0]);
        switch (contentType)
        {
            case Constant.TAB_TYPE_SAY_WACTH:
            case Constant.TAB_TYPE_SAY_LIKE:
                iService=new ImpSay();
                iService.getSayList(this,type);
                break;
            case Constant.TAB_TYPE_LIKE:
                iService=new ImpYuLu();
                iService.getAllT(this,type);
                break;
        }

    }

    public ImpPHome(IViewHome iViewHome) {
        this.iViewHome = iViewHome;
    }

    @Override
    public void onSuccess(Object t) {
        if (t instanceof YiJuAndYiShuoResponse)
        {
            dataPreprocess((YiJuAndYiShuoResponse) t);
        }

    }
    private void dataPreprocess(YiJuAndYiShuoResponse d){
        DataEntity dataEntity = d.getData();
        totalCount=dataEntity.getCount();
        List<YiJuAndYiShuoEntity> list = dataEntity.getItems();
        if (!lastType.equals(contentType))
        {
            pullMore=false;
        }
        lastType=contentType;
        if (!pullMore)
        {
            iViewHome.pullMoreComlite();
        }else {
            iViewHome.getData().clear();
            iViewHome.refreshComplite();
        }
        if (list!=null&list.size()>0)
        {
            iViewHome.getData().addAll(list);
        }
    }

    public void onRefresh() {
        pullMore=false;
        pageNum=1;
        getAllT(pageNum+"",contentType);
    }

    @Override
    public void onLoadMoreRequested() {
        if (iViewHome.getData().size() < totalCount) {
            pullMore=true;
            pageNum++;
            getAllT(pageNum+"",contentType);
        } else {
            iViewHome.pullMoreNoMore();
        }
    }



}
